/***************************************************************************
*   Copyright (C) 2005 by Alexander Nemish  *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#ifndef BOOKWIDGET_H
#define BOOKWIDGET_H

#include <qwidget.h>
#include <qevent.h>
#include <qpixmap.h>
#include <qthread.h>
#include <kurl.h>
//#include "ktextprogressdlg.h"

class QStringList;
class QRect;
class Renderer;
//class KURL;

/**
 *	@author Alexander
 */
class BookWidget : public QWidget
{
	Q_OBJECT
	friend class TextThread;
public:
	BookWidget( QWidget *parent = 0, const char *name = 0 );

	~BookWidget();

	virtual void openURL( const KURL & url );
	virtual QString currentURL();
	void paintEvent (QPaintEvent *);
	void setFont( const QFont & );
	void setCurrentPage(int number);
	int  currentPage() const { return m_currentPage; };
	void nextPage();
	void prevPage();
	void firstPage();
	void lastPage();
	QSize minimumSizeHint () const;
	void setupPageSize();
	//const TextThread * thread() const {return m_thread;}
signals:
	/**
	 * Use this signal to change the content of the statusbar
	 */
	void signalChangeStatusbar(const QString& text);

	/**
	 * Use this signal to change the content of the caption
	 */
	void signalChangeCaption(const QString& text);

	void loaded(int);
protected:
	const QRect rectLeftPage() const;
	const QRect rectRightPage() const;
	void mousePressEvent(QMouseEvent *);
	void keyPressEvent (QKeyEvent * e);
	void resizeEvent (QResizeEvent * e);
	void wheelEvent (QWheelEvent * e);
	void clearAll();

private:
	KURL	m_url;
	int m_currentPage;
	int m_left_margin;
	int m_right_margin;
	int m_top_margin;
	int m_bottom_margin;
	int m_middle_margin;
	std::auto_ptr<Renderer> m_renderer;
	//	TextProcessDialog * m_process;
};

#endif
